package org.loofer.uiframework;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ListView;
import org.loofer.uiframework.helper.DataListFooterViewHelper;
import org.loofer.uiframework.helper.StateViewHelper;
import org.loofer.uikit.DataListFooterView;
import org.loofer.uikit.StateView;
import org.loofer.uikit.StateView.State;
import java.util.List;

public abstract class PageDataLoadingFragment<MODEL> extends BaseFragment implements PageDataLoadingView<MODEL> {
    private DataListFooterView mDataListFooterView;
    private ListView mInjectListView;
    private LayoutInflater mLayoutInflater;
    private StateView mStateView;

    protected abstract LifeCircle getPresenter();

    protected abstract View onCreateSuccessView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle);

    protected abstract void onRetryClick();

    public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        this.mLayoutInflater = inflater;
        this.mStateView = new StateViewHelper().inject(onCreateSuccessView(inflater, container, savedInstanceState), PageDataLoadingFragment$$Lambda$1.lambdaFactory$(this));
        return this.mStateView;
    }

    private /* synthetic */ void lambda$onCreateView$1(View v) {
        onRetryClick();
    }

    protected LayoutInflater getLayoutInflater() {
        return this.mLayoutInflater;
    }

    public void onResume() {
        super.onResume();
        getPresenter().resume();
    }

    public void onPause() {
        super.onPause();
        getPresenter().pause();
    }

    public void onDestroy() {
        super.onDestroy();
        getPresenter().destroy();
    }

    public void showLoading() {
        this.mStateView.setState(State.LOADING);
    }

    public void showFailure(String message) {
        this.mStateView.setState(State.FAILED);
    }

    public void showNoData() {
        this.mStateView.setState(State.NO_DATA);
    }

    public void showSuccess() {
        this.mStateView.setState(State.SUCCESS);
    }

    public void setData(MODEL model) {
    }

    public void setData(List<MODEL> list) {
    }

    public void appendData(List<MODEL> list) {
    }

    public void showNextPageLoading() {
        if (this.mDataListFooterView != null) {
            this.mDataListFooterView.showLoadingAnim();
        }
    }

    public void showNextPageFailure() {
        if (this.mDataListFooterView != null) {
            this.mDataListFooterView.showLoadFailText();
        }
    }

    public void showNextPageSuccess() {
        if (this.mDataListFooterView != null) {
            this.mDataListFooterView.hide();
        }
    }

    public void showAllPageLoaded() {
        if (this.mDataListFooterView != null) {
            this.mDataListFooterView.showLastPageText("共" + ((this.mInjectListView.getAdapter().getCount() - this.mInjectListView.getFooterViewsCount()) - this.mInjectListView.getHeaderViewsCount()) + "个");
        }
    }

    protected void addFooterLoadingViewToList(ListView injectListView, OnClickListener retryListener) {
        this.mInjectListView = injectListView;
        this.mDataListFooterView = new DataListFooterViewHelper().inject(this.mInjectListView, retryListener);
        this.mInjectListView.addFooterView(this.mDataListFooterView);
    }
}
